<?php
/*
 This file provides the functions to deal with Vacancy Issues
 */
include_once 'dbconfig.php';

class Vacancy {

	function Vacancy() {
		/*
		 This is the constructor of Vacancy class
		 Connect to the database
		 */
		mysql_connect(DBSERVER, DBUSER, DBPASS);  // from dbconfig.php
		$selectdb = mysql_select_db(DBNAME);
	}	

        function get_title ($vacancy_id) {
		/*
		Select the specific vacancy title and return in $title
		 */
			$sql = "SELECT vacancy_title FROM vacancy WHERE vacancy_id = '" .$vacancy_id. "'";
			$result = mysql_query($sql);
			$row = mysql_fetch_assoc($result);
			$title = $row['vacancy_title']. ", " .$row['postal_id'];
			return $title;


	}

        function get_vacancy_detail($vacancy_id) {
		/*
		Select a specific vacancy based on its vacancy_id and print all detail information about it
		*/


		$sql = "SELECT * FROM vacancy WHERE vacancy_id = '" .$vacancy_id. "'";
		$result = mysql_query($sql);
		$one_vacancy = mysql_fetch_assoc($result);
		/*
		$row = mysql_fetch_assoc($result);
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
		$return_array[] = $row;
		}
		*/
		return $one_vacancy;
	}
	
	function get_message($vacancy_id){
	
		$sql = "SELECT * FROM message WHERE vacancy_id='".$vacancy_id."'";
		$result = mysql_query($sql);
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}

	function get_address($vacancy_id) {
		/*
		Select a specific user name and return the name in $row['name']
		*/

		$sql = "SELECT vacancy_block,vacancy_address,postal_id FROM vacancy WHERE vacancy_id = '" .$vacancy_id. "'";
		$result = mysql_query($sql);
		$row = mysql_fetch_assoc($result);
		$address = $row['vacancy_block']. ", " .$row['vacancy_address']. ", " .$row['postal_id'];
		return $address;
    }
	
	function do_post_message($vacancy_id, $member_id, $content) {
		
		$sql = "INSERT INTO message (member_id, vacancy_id, content) VALUES ('$member_id', '$vacancy_id', '$content')";
		if ($result = mysql_query($sql))
		{
		$success = "true";
		}
		else
		{
		$success = "false";
		}
		return $success;
	}
	
	function set_location_id($postal_id) {
		/*
		Set location ID
		*/
	
		$sql= "SELECT SUBSTR('" .$postal_id. "', 1, 2) AS location_id";
		$result = mysql_query($sql);
		$row = mysql_fetch_assoc($result);
		return $row['location_id'];
	}

    function list_all_vacancy()
	{
		$sql = "SELECT * FROM vacancy";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}

	function list_editable_vacancy($landlord_id)
	{
		$sql = "SELECT vacancy_id, vacancy_title, vacancy_address, postal_id, vacancy_available, vacancy_description, 		 vacancy_photo,add_time FROM vacancy WHERE landlord_id='" .$landlord_id. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}	
		return $return_array;
	}
	
	function list_edit_vacancy($vacancy_id)
	{
		$sql = "SELECT * FROM vacancy WHERE vacancy_id='" .$vacancy_id. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}	
		return $return_array;
	}
	
	function add_vacancy($landlord_id, $location_id, $title, $type, $room, $rental, $unit, $block, $address,
                            $postal_id, $sharing, $description, $image) {
		
		if ($image == "") {
                    $sql1 = "INSERT INTO vacancy (landlord_id, location_id, vacancy_type, vacancy_title, vacancy_room, vacancy_rental,
                vacancy_unit, vacancy_block, vacancy_address, postal_id, vacancy_sharing, vacancy_available,
                vacancy_description, vacancy_photo, add_time) VALUES
                ('$landlord_id', '$location_id', '$type', '$title', '$room', '$rental', '$unit', '$block', '$address', '$postal_id', '$sharing',
                '1', '$description', 'no_image.jpg', now())";
		$result1 = mysql_query($sql1) or die (mysql_error());
		} else {
                    $sql2 = "INSERT INTO vacancy (landlord_id, location_id, vacancy_type, vacancy_title, vacancy_room, vacancy_rental,
                vacancy_unit, vacancy_block, vacancy_address, postal_id, vacancy_sharing, vacancy_available,
                vacancy_description, vacancy_photo, add_time) VALUES
                ('$landlord_id', '$location_id', '$type', '$title', '$room', '$rental', '$unit', '$block', '$address', '$postal_id', '$sharing',
                '1', '$description', '$image', now())";
		$result2 = mysql_query($sql2) or die (mysql_error());
		}
	}
	
	function update_vacancy($landlord_id, $location_id, $title, $type, $room, $rental, $unit, $block, $address,
                                $postal_id, $sharing, $description, $image, $vacancy_id)
	{
		if ($image == "") {
			$sql = "UPDATE vacancy SET location_id= '" .$location_id. "' , vacancy_title= '" .$title. "' ,
        vacancy_type= '" .$type. "' , vacancy_room= '" .$room. "' , vacancy_rental= '" .$rental. "' ,
        vacancy_unit= '" .$unit. "' , vacancy_block= '" .$block. "' , vacancy_address= '" .$address. "',
        postal_id= '" .$postal_id. "' , vacancy_sharing= '" .$sharing. "' , vacancy_description= '" .$description. "' , vacancy_photo='no_image.jpg'
        WHERE vacancy_id= " .$vacancy_id;
			$result = mysql_query($sql) or die(mysql_error());
		} 
		else {
			$sql = "UPDATE vacancy SET location_id= '" .$location_id. "' , vacancy_title= '" .$title. "' ,
        vacancy_type= '" .$type. "' , vacancy_room= '" .$room. "' , vacancy_rental= '" .$rental. "' ,
        vacancy_unit= '" .$unit. "' , vacancy_block= '" .$block. "' , vacancy_address= '" .$address. "',
        postal_id= '" .$postal_id. "' , vacancy_sharing= '" .$sharing. "' , vacancy_description= '" .$description. "' , vacancy_photo='" .$image. "'
        WHERE vacancy_id= '" .$vacancy_id. "'";
			$result = mysql_query($sql) or die(mysql_error());
		}
	}
	
	function get_region_vacancy($region_id) {
		
		$sql = "SELECT vacancy_id, landlord_id, vacancy_title, vacancy_address, postal_id, vacancy_available, vacancy_description,
		vacancy_photo,add_time, COUNT(*) AS count FROM vacancy,location WHERE vacancy.location_id = location.location_id AND 
		location.region_id = '" .$region_id. "' GROUP BY vacancy_id";
		$result = mysql_query($sql) or die(mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}
	
	function get_region_aggregate($region_id) {
		
		$sql = "SELECT COUNT(*) AS count FROM vacancy,location WHERE vacancy.location_id = location.location_id AND 
		location.region_id = '" .$region_id. "'";
		$result = mysql_query($sql) or die(mysql_error());
		$row = mysql_fetch_assoc($result);
		return $row['count'];
		
	}

    function search_function($search)
	{
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}

    function search_rental($rental)
	{
            if($rental=="price1") {
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental < 200";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price2") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental BETWEEN 200 AND 399";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price3") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental BETWEEN 400 AND 599";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price4") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental BETWEEN 600 AND 799";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price5") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental BETWEEN 800 AND 999";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price6") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental BETWEEN 1000 AND 1199";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            else {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental > 1200";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            return $return_array;
	}

        function search_house($house)
	{
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}

    function search_by_all($house, $rental, $search)
	{
            if($rental=="price1") {
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental < 200 AND vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "')";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price2") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 200 AND 399";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price3") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 400 AND 599";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price4") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 600 AND 799";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price5") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 800 AND 999";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price6") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 1000 AND 1199";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            else {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental > 1200 AND vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "')";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            return $return_array;
	}

    function search_rental_search($rental, $search)
	{
            if($rental=="price1") {
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental < 200 AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "')";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price2") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 200 AND 399";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price3") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 400 AND 599";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price4") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 600 AND 799";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price5") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 800 AND 999";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price6") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "') AND vacancy_rental BETWEEN 1000 AND 1199";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            else {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental > 1200 AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "')";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            return $return_array;
	}

    function search_house_search($house, $search)
	{
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND (vacancy_address LIKE '" .$search. "%'OR vacancy_address LIKE '%" .$search. "%' OR vacancy_address LIKE '%" .$search. "')";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
		return $return_array;
	}

    function search_house_rental($house, $rental)
	{
            if($rental=="price1") {
		$sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental < 200 AND vacancy_type='" .$house. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price2") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND vacancy_rental BETWEEN 200 AND 399";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price3") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND vacancy_rental BETWEEN 400 AND 599";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price4") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND vacancy_rental BETWEEN 600 AND 799";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price5") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND vacancy_rental BETWEEN 800 AND 999";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            elseif ($rental=="price6") {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_type='" .$house. "' AND vacancy_rental BETWEEN 1000 AND 1199";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            else {
                $sql="SELECT vacancy_id, vacancy_title, vacancy_unit, vacancy_block, vacancy_address, vacancy_sharing, postal_id, vacancy_available, vacancy_description, vacancy_rental, vacancy_photo,add_time FROM vacancy WHERE vacancy_rental > 1200 AND vacancy_type='" .$house. "'";
		$result = mysql_query($sql) or die (mysql_error());
		$return_array = array();
		while ($row = mysql_fetch_assoc($result)) {
			$return_array[] = $row;
		}
            }
            return $return_array;
	}

	function delete_vacancy($vacancy_id)
	{
		$sql="DELETE FROM vacancy WHERE vacancy_id=" .$vacancy_id;
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}
	
	function delete_message($message_id)
	{
		$sql="DELETE FROM message WHERE message_id=" .$message_id;
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}

        function delete_member_vacancy($landlord_id)
	{
		$sql="DELETE FROM vacancy WHERE landlord_id=" .$landlord_id;
		$result=mysql_query($sql) or die(mysql_error());
		return $result;
	}

    function get_landlord_id_on_map($vacancy_id)
    {
        $sql = "SELECT landlord_id FROM vacancy WHERE vacancy_id = '" .$vacancy_id. "'";
        $result = mysql_query($sql);
        $row = mysql_fetch_assoc($result);
        return $row['landlord_id'];
	}
}
?>